package com.levelup.cr.services.impl;

import com.levelup.cr.dao.fs.FSNodeReader;
import com.levelup.cr.model.Node;
import com.levelup.cr.model.entity.Product;
import com.levelup.cr.services.RepositoryResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 15.08.13
 * Time: 20:30
 * To change this template use File | Settings | File Templates.
 */
@Service("repositoryResolver")
public class RepositoryResolverImpl implements RepositoryResolver {

    @Autowired
    private FSNodeReader fsNodeReader;

    public void setFsNodeReader(FSNodeReader fsNodeReader) {
        this.fsNodeReader = fsNodeReader;
    }

    @Override
    public Node findNodeById(String id) {
        Node result = new Node();
        HashMap<String,Object> properties = new HashMap<String, Object>();
        properties.put("view","product");
        properties.put(Product.PROPERTY_NAME,"Product 1");
        properties.put(Product.PROPERTY_DESC,"Product 1 Description");
        properties.put(Product.PROPERTY_PRICE, 1.2f);
        properties.put(Node.NODE_TYPE_PROPERTY,"Product");

        result.setProperties(properties);
        result.setRoot(true);
        result.setName(id);
        return result;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public Node getNodeByPath(String path, int nestedLevel){
        return fsNodeReader.readNode(path,nestedLevel);
    }
}
